package com.neusoft.neuiotms.dcam.workflow.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcam.workflow.dto.PeifaSLDTO;
import com.neusoft.neuiotms.dcam.workflow.service.PeifaSLService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "总行配发工单")
@RestController
@RequestMapping(value = "/api/w/workflow/peifasl")
public class PeifaSLController {

    @Autowired
    private PeifaSLService peifaSLService;

    @ApiOperation("新增资产配发申请")
    @PostMapping
    public ResultDTO<PeifaSLDTO> create(@RequestBody final PeifaSLDTO dto,
            final UserBean user) {
        return ResultDTO.success(this.peifaSLService.create(dto, user));
    }

    @ApiOperation("查看资产配发申请")
    @GetMapping("/{workOrderNum}/{taskId}")
    public ResultDTO<PeifaSLDTO> details(@PathVariable final String workOrderNum,
            @PathVariable final String taskId,
            final UserBean user) {
        return ResultDTO.success(this.peifaSLService.detail(workOrderNum, taskId, user));
    }

    @ApiOperation("新增资产配发确认")
    @PostMapping("confirm")
    public ResultDTO<Void> confirmCreate(@RequestBody final PeifaSLDTO dto,
            final UserBean user) {
        this.peifaSLService.confirmCreate(dto, user);
        return ResultDTO.success();
    }

    @ApiOperation("查看资产配发确认")
    @GetMapping("confirm/{workOrderNum}/{taskId}")
    public ResultDTO<PeifaSLDTO> confirmDetails(@PathVariable final String workOrderNum,
            @PathVariable final String taskId,
            final UserBean user) {
        return ResultDTO.success(this.peifaSLService.confirmDetails(workOrderNum, taskId, user));
    }

    @ApiOperation("分页查询入库单")
    @GetMapping("/p")
    public PageResultDTO<PeifaSLDTO> search(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.peifaSLService.search(pageable, searchable));
    }

    @ApiOperation("查看详情")
    @GetMapping("/{id}")
    public ResultDTO<PeifaSLDTO> details(@PathVariable final Long id) {
        return ResultDTO.success(this.peifaSLService.detail(id));
    }

}
